/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package PresentationTier;

import BusinessTier.AdicaoBUS;
import BusinessTier.AditamentoBUS;
import BusinessTier.ContratadoBUS;
import BusinessTier.ContratoBUS;
import BusinessTier.LiquidacaoBUS;
import EntitiesTier.ClContratado;
import EntitiesTier.ClContrato;
import Models.AdicaoTableModel;
import Models.AditamentoTableModel;
import Models.LiquidacaoTableModel;
import PresentationTier.Pesquisa.GUIContratadoPesquisar;
import PresentationTier.Pesquisa.GUIContratoPesquisar;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.beans.PropertyVetoException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

/**
 *
 * @author douglas
 */
public class GUICadContrato extends javax.swing.JInternalFrame {
    ClContratado clcodo;
    ClContrato cl;
    /**
     * Creates new form GUICadContrato
     */
    public GUICadContrato() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jToggleButton1 = new javax.swing.JToggleButton();
        buttonGroup1 = new javax.swing.ButtonGroup();
        jPanel1 = new javax.swing.JPanel();
        lblVlrIni = new javax.swing.JLabel();
        edtVlrIni = new javax.swing.JTextField();
        lvlDtaAss = new javax.swing.JLabel();
        edtDataAssinatura = new javax.swing.JFormattedTextField();
        cbSituacao = new javax.swing.JComboBox();
        lvlDataFim = new javax.swing.JLabel();
        edtDatafim = new javax.swing.JTextField();
        edtVlrFim = new javax.swing.JTextField();
        lblSetor = new javax.swing.JLabel();
        lblVlrFim = new javax.swing.JLabel();
        lvlStatus = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        edtDuracao = new javax.swing.JTextField();
        lblNum = new javax.swing.JLabel();
        edtSetor = new javax.swing.JTextField();
        edtCont = new javax.swing.JTextField();
        edtCodo = new javax.swing.JTextField();
        lvlStatus1 = new javax.swing.JLabel();
        edtNmCodo = new javax.swing.JTextField();
        btnCodo = new javax.swing.JButton();
        rbDias = new javax.swing.JRadioButton();
        rbMes = new javax.swing.JRadioButton();
        pnOpc = new javax.swing.JPanel();
        btnNovo = new javax.swing.JButton();
        btnCancelar = new javax.swing.JButton();
        btnExcluir = new javax.swing.JButton();
        btnEdit = new javax.swing.JButton();
        btnSair = new javax.swing.JButton();
        btnGravar = new javax.swing.JButton();
        btnProcurar = new javax.swing.JButton();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        pnAdicao = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblAdic = new javax.swing.JTable();
        pnAditamento = new javax.swing.JPanel();
        jScrollPane4 = new javax.swing.JScrollPane();
        tblAdit = new javax.swing.JTable();
        pnLiquidacao = new javax.swing.JPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        tblLiq = new javax.swing.JTable();

        jToggleButton1.setText("jToggleButton1");

        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        setMaximumSize(new java.awt.Dimension(600, 550));
        setMinimumSize(new java.awt.Dimension(545, 510));
        setPreferredSize(new java.awt.Dimension(545, 510));

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Dados Contrato"));
        jPanel1.setAutoscrolls(true);
        jPanel1.setMaximumSize(new java.awt.Dimension(525, 200));
        jPanel1.setMinimumSize(new java.awt.Dimension(525, 180));
        jPanel1.setPreferredSize(new java.awt.Dimension(525, 180));

        lblVlrIni.setText("Valor Inicial");

        lvlDtaAss.setText("Data Assinatura");

        edtDataAssinatura.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                edtDataAssinaturaActionPerformed(evt);
            }
        });

        cbSituacao.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Vigente", "Renovado", "Prorrogado", "Rescindido", "Cumprido" }));
        cbSituacao.setToolTipText("Vigente\nRenovado\nProrrogado\nRescindido\nCumprido"); // NOI18N

        lvlDataFim.setText("Data Final(Previsto) .:");

        edtVlrFim.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                edtVlrFimActionPerformed(evt);
            }
        });

        lblSetor.setText("Setor");

        lblVlrFim.setText("Valor Final");

        lvlStatus.setText("Status");

        jLabel1.setText("Duração");

        lblNum.setText("Número");

        edtCont.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                edtContActionPerformed(evt);
            }
        });

        edtCodo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                edtCodoActionPerformed(evt);
            }
        });

        lvlStatus1.setText("Contratado");

        edtNmCodo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                edtNmCodoActionPerformed(evt);
            }
        });

        btnCodo.setText("jButton1");
        btnCodo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCodoActionPerformed(evt);
            }
        });

        buttonGroup1.add(rbDias);
        rbDias.setText("Dias");

        buttonGroup1.add(rbMes);
        rbMes.setText("Mês");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblNum)
                            .addComponent(edtCont, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblSetor, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(edtSetor, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lvlDtaAss)
                            .addComponent(edtDataAssinatura, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(edtDuracao, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(rbMes)
                            .addComponent(rbDias))
                        .addGap(29, 29, 29))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(edtCodo, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(edtNmCodo, javax.swing.GroupLayout.PREFERRED_SIZE, 384, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(btnCodo, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(lvlStatus)
                                        .addGap(106, 106, 106)
                                        .addComponent(lblVlrIni))
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(cbSituacao, javax.swing.GroupLayout.PREFERRED_SIZE, 127, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(edtVlrIni, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(edtVlrFim, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(lblVlrFim))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(lvlDataFim)
                                    .addComponent(edtDatafim, javax.swing.GroupLayout.PREFERRED_SIZE, 143, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addComponent(lvlStatus1))
                        .addGap(8, 8, 8))))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblNum)
                    .addComponent(lblSetor)
                    .addComponent(lvlDtaAss)
                    .addComponent(jLabel1)
                    .addComponent(rbDias))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(edtCont, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(edtSetor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(edtDataAssinatura, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(edtDuracao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(rbMes))
                .addGap(7, 7, 7)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(lvlDataFim)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(lblVlrIni)
                                .addComponent(lvlStatus, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(cbSituacao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(edtVlrIni, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(edtDatafim, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(lblVlrFim)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(edtVlrFim, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lvlStatus1, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(edtCodo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(edtNmCodo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnCodo))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pnOpc.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        pnOpc.setPreferredSize(new java.awt.Dimension(790, 80));
        pnOpc.setLayout(null);

        btnNovo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icones/add.png"))); // NOI18N
        btnNovo.setText("Novo");
        btnNovo.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnNovo.setMaximumSize(new java.awt.Dimension(50, 50));
        btnNovo.setMinimumSize(new java.awt.Dimension(50, 50));
        btnNovo.setPreferredSize(new java.awt.Dimension(50, 50));
        btnNovo.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnNovo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnNovoActionPerformed(evt);
            }
        });
        pnOpc.add(btnNovo);
        btnNovo.setBounds(47, 10, 75, 60);

        btnCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icones/cancel.png"))); // NOI18N
        btnCancelar.setText("Cancelar");
        btnCancelar.setEnabled(false);
        btnCancelar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnCancelar.setMaximumSize(new java.awt.Dimension(100, 25));
        btnCancelar.setMinimumSize(new java.awt.Dimension(100, 25));
        btnCancelar.setPreferredSize(new java.awt.Dimension(100, 25));
        btnCancelar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelarActionPerformed(evt);
            }
        });
        pnOpc.add(btnCancelar);
        btnCancelar.setBounds(130, 10, 75, 60);

        btnExcluir.setMaximumSize(new java.awt.Dimension(50, 50));
        btnExcluir.setMinimumSize(new java.awt.Dimension(50, 50));
        btnExcluir.setPreferredSize(new java.awt.Dimension(50, 50));
        btnExcluir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnExcluirActionPerformed(evt);
            }
        });
        pnOpc.add(btnExcluir);
        btnExcluir.setBounds(10, 10, 10, 20);

        btnEdit.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icones/edit.gif"))); // NOI18N
        btnEdit.setText("Editar");
        btnEdit.setEnabled(false);
        btnEdit.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnEdit.setMaximumSize(new java.awt.Dimension(50, 50));
        btnEdit.setMinimumSize(new java.awt.Dimension(50, 50));
        btnEdit.setPreferredSize(new java.awt.Dimension(50, 50));
        btnEdit.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnEdit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEditActionPerformed(evt);
            }
        });
        pnOpc.add(btnEdit);
        btnEdit.setBounds(290, 10, 75, 60);

        btnSair.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icones/Exit.png"))); // NOI18N
        btnSair.setText("Sair");
        btnSair.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnSair.setMaximumSize(new java.awt.Dimension(50, 50));
        btnSair.setMinimumSize(new java.awt.Dimension(50, 50));
        btnSair.setPreferredSize(new java.awt.Dimension(50, 50));
        btnSair.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnSair.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSairActionPerformed(evt);
            }
        });
        pnOpc.add(btnSair);
        btnSair.setBounds(450, 10, 75, 60);

        btnGravar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icones/Gravar.png"))); // NOI18N
        btnGravar.setText("Gravar");
        btnGravar.setEnabled(false);
        btnGravar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnGravar.setMaximumSize(new java.awt.Dimension(50, 50));
        btnGravar.setMinimumSize(new java.awt.Dimension(50, 50));
        btnGravar.setPreferredSize(new java.awt.Dimension(50, 50));
        btnGravar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnGravar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGravarActionPerformed(evt);
            }
        });
        pnOpc.add(btnGravar);
        btnGravar.setBounds(210, 10, 75, 60);

        btnProcurar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icones/pesquisar.png"))); // NOI18N
        btnProcurar.setText("Buscar");
        btnProcurar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnProcurar.setMaximumSize(new java.awt.Dimension(50, 50));
        btnProcurar.setMinimumSize(new java.awt.Dimension(50, 50));
        btnProcurar.setPreferredSize(new java.awt.Dimension(50, 50));
        btnProcurar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnProcurar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnProcurarActionPerformed(evt);
            }
        });
        pnOpc.add(btnProcurar);
        btnProcurar.setBounds(370, 10, 75, 60);

        pnAdicao.setBorder(javax.swing.BorderFactory.createTitledBorder(""));

        tblAdic.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null}
            },
            new String [] {
                "Data Adição", "Motivo", "Tempo"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Object.class, java.lang.String.class, java.lang.Integer.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        jScrollPane1.setViewportView(tblAdic);

        javax.swing.GroupLayout pnAdicaoLayout = new javax.swing.GroupLayout(pnAdicao);
        pnAdicao.setLayout(pnAdicaoLayout);
        pnAdicaoLayout.setHorizontalGroup(
            pnAdicaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnAdicaoLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 496, Short.MAX_VALUE)
                .addContainerGap())
        );
        pnAdicaoLayout.setVerticalGroup(
            pnAdicaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnAdicaoLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 144, Short.MAX_VALUE)
                .addContainerGap())
        );

        jTabbedPane1.addTab("Adição", pnAdicao);

        pnAditamento.setBorder(javax.swing.BorderFactory.createTitledBorder(""));

        tblAdit.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null}
            },
            new String [] {
                "Data Aditamento", "Motivo", "R$"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Object.class, java.lang.String.class, java.lang.Float.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        tblAdit.setName(""); // NOI18N
        jScrollPane4.setViewportView(tblAdit);
        tblAdit.getColumnModel().getColumn(0).setResizable(false);
        tblAdit.getColumnModel().getColumn(2).setResizable(false);

        javax.swing.GroupLayout pnAditamentoLayout = new javax.swing.GroupLayout(pnAditamento);
        pnAditamento.setLayout(pnAditamentoLayout);
        pnAditamentoLayout.setHorizontalGroup(
            pnAditamentoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnAditamentoLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 496, Short.MAX_VALUE)
                .addContainerGap())
        );
        pnAditamentoLayout.setVerticalGroup(
            pnAditamentoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnAditamentoLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 144, Short.MAX_VALUE)
                .addContainerGap())
        );

        jTabbedPane1.addTab("Aditamento", pnAditamento);

        pnLiquidacao.setBorder(javax.swing.BorderFactory.createTitledBorder(""));

        tblLiq.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null}
            },
            new String [] {
                "Data Liquidação", "Nota Fiscal/Documento Fiscal", "R$"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Object.class, java.lang.String.class, java.lang.Float.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        jScrollPane3.setViewportView(tblLiq);
        tblLiq.getColumnModel().getColumn(0).setResizable(false);
        tblLiq.getColumnModel().getColumn(2).setResizable(false);

        javax.swing.GroupLayout pnLiquidacaoLayout = new javax.swing.GroupLayout(pnLiquidacao);
        pnLiquidacao.setLayout(pnLiquidacaoLayout);
        pnLiquidacaoLayout.setHorizontalGroup(
            pnLiquidacaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnLiquidacaoLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 496, Short.MAX_VALUE)
                .addContainerGap())
        );
        pnLiquidacaoLayout.setVerticalGroup(
            pnLiquidacaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnLiquidacaoLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 144, Short.MAX_VALUE)
                .addContainerGap())
        );

        jTabbedPane1.addTab("Liquidação", pnLiquidacao);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(pnOpc, javax.swing.GroupLayout.DEFAULT_SIZE, 529, Short.MAX_VALUE)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jTabbedPane1))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(6, 6, 6)
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 199, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(pnOpc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnSairActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSairActionPerformed
        try {
            this.setClosed(true);
        } catch (PropertyVetoException ex) {
            Logger.getLogger(GUICadContrato.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_btnSairActionPerformed

    private void edtCodoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_edtCodoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_edtCodoActionPerformed

    private void edtContActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_edtContActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_edtContActionPerformed

    private void edtVlrFimActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_edtVlrFimActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_edtVlrFimActionPerformed

    private void edtDataAssinaturaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_edtDataAssinaturaActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_edtDataAssinaturaActionPerformed

    private void edtNmCodoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_edtNmCodoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_edtNmCodoActionPerformed

    private void btnCodoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCodoActionPerformed
        Dimension tela =  Toolkit.getDefaultToolkit().getScreenSize();
          GUIContratadoPesquisar tPesqContratado = new GUIContratadoPesquisar(null, true);
          tPesqContratado.setLocation((tela.width- tPesqContratado.getSize().width)/2,
                       (tela.height- tPesqContratado.getSize().height)/2);
          tPesqContratado.setVisible(true);
        //Acrescentar essas linhas
        cl.setCONT_CODFOR(tPesqContratado.idcontratado);
       
        if (cl.getCONT_CODFOR() > 0)
        {
            PreencheContratado();
            
        }
        tPesqContratado.setVisible(false);


            // TODO add your handling code here:
    }//GEN-LAST:event_btnCodoActionPerformed

    private void btnNovoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNovoActionPerformed
        cl = new ClContrato();
        Ativa();
        LimpaCampos();
        rbDias.setSelected(true);
    }//GEN-LAST:event_btnNovoActionPerformed

    private void btnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarActionPerformed
        if (cl.getCONT_COD() == 0)
        {
            cl = null;
            Desativa();
        }
        else
        {
            Desativa();
            PreencheCampos();
        }
    }//GEN-LAST:event_btnCancelarActionPerformed

    private void btnExcluirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnExcluirActionPerformed
        if(cl.getCONT_COD() > 0)
        {
            if (JOptionPane.showConfirmDialog(null,"Deseja Excluir o contrato " + cl.getCONT_NOME() +" ?") == JOptionPane.YES_OPTION)
            {
                ContratadoBUS bus = new ContratadoBUS();
                try 
                {
                    bus.excluir(cl.getCONT_COD());
                    LimpaCampos();
                } catch (Exception ex) {
                    Logger.getLogger(GUICadContratado.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    }//GEN-LAST:event_btnExcluirActionPerformed

    private void btnEditActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEditActionPerformed
        if( cl != null)
            Ativa();
    }//GEN-LAST:event_btnEditActionPerformed

    private void btnGravarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGravarActionPerformed
        
        ContratoBUS bus = new ContratoBUS();
        try 
        {
            carregadadoscl();
        } 
        catch (ParseException ex) 
        {
            Logger.getLogger(GUICadContrato.class.getName()).log(Level.SEVERE, null, ex);
        }
        if (cl.getCONT_COD() == 0)
        {
            try {
                cl.setCONT_COD(bus.inserir(cl));
            } 
            catch (Exception ex) 
            {
                Logger.getLogger(GUICadContratado.class.getName()).log(Level.SEVERE, null, ex);
            }
            finally
            {
                Desativa();
            }
        }
        else
        {
            try 
            {
                bus.atualizar(cl);
            } 
            catch (Exception ex) 
            {
                Logger.getLogger(GUILancAdic.class.getName()).log(Level.SEVERE, null, ex);
            }
            finally
            {
                Desativa();
            }
        }
    }//GEN-LAST:event_btnGravarActionPerformed

    private void btnProcurarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnProcurarActionPerformed
          Dimension tela =  Toolkit.getDefaultToolkit().getScreenSize();
          GUIContratoPesquisar tPesqContrato = new GUIContratoPesquisar(null, true);
          tPesqContrato.setLocation((tela.width- tPesqContrato.getSize().width)/2,
                       (tela.height- tPesqContrato.getSize().height)/2);
          tPesqContrato.setVisible(true);
        
        int cont = tPesqContrato.cont;
       
        //this.edtContrato.setEnabled(true);
        //this.edtContrato.requestFocus();
        if (cont > 0)
        {
            //this.lblCodCont.setText(String.valueOf(idCliente));
            ContratoBUS busc = new ContratoBUS();
            try 
            {
                cl = busc.buscar(cont);
                PreencheCampos();
            } catch (Exception ex) {
                Logger.getLogger(GUICadContratado.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        tPesqContrato.setVisible(false);
    }//GEN-LAST:event_btnProcurarActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCancelar;
    private javax.swing.JButton btnCodo;
    private javax.swing.JButton btnEdit;
    private javax.swing.JButton btnExcluir;
    private javax.swing.JButton btnGravar;
    private javax.swing.JButton btnNovo;
    private javax.swing.JButton btnProcurar;
    private javax.swing.JButton btnSair;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JComboBox cbSituacao;
    private javax.swing.JTextField edtCodo;
    private javax.swing.JTextField edtCont;
    private javax.swing.JFormattedTextField edtDataAssinatura;
    private javax.swing.JTextField edtDatafim;
    private javax.swing.JTextField edtDuracao;
    private javax.swing.JTextField edtNmCodo;
    private javax.swing.JTextField edtSetor;
    private javax.swing.JTextField edtVlrFim;
    private javax.swing.JTextField edtVlrIni;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JToggleButton jToggleButton1;
    private javax.swing.JLabel lblNum;
    private javax.swing.JLabel lblSetor;
    private javax.swing.JLabel lblVlrFim;
    private javax.swing.JLabel lblVlrIni;
    private javax.swing.JLabel lvlDataFim;
    private javax.swing.JLabel lvlDtaAss;
    private javax.swing.JLabel lvlStatus;
    private javax.swing.JLabel lvlStatus1;
    private javax.swing.JPanel pnAdicao;
    private javax.swing.JPanel pnAditamento;
    private javax.swing.JPanel pnLiquidacao;
    private javax.swing.JPanel pnOpc;
    private javax.swing.JRadioButton rbDias;
    private javax.swing.JRadioButton rbMes;
    private javax.swing.JTable tblAdic;
    private javax.swing.JTable tblAdit;
    private javax.swing.JTable tblLiq;
    // End of variables declaration//GEN-END:variables

    private void Ativa() {
        edtCodo.setEditable(true);
        edtCont.setEditable(true);
        edtDataAssinatura.setEditable(true);
        edtDatafim.setEditable(true);
        edtDuracao.setEditable(true);
        edtNmCodo.setEditable(true);
        edtSetor.setEditable(true);
        edtVlrFim.setEditable(true);
        edtVlrIni.setEditable(true);
        cbSituacao.setEditable(true);
        btnCodo.setEnabled(true);
    }

    private void Desativa() {
        edtCodo.setEditable(false);
        edtCont.setEditable(false);
        edtDataAssinatura.setEditable(false);
        edtDatafim.setEditable(false);
        edtDuracao.setEditable(false);
        edtNmCodo.setEditable(false);
        edtSetor.setEditable(false);
        edtVlrFim.setEditable(false);
        edtVlrIni.setEditable(false);
        cbSituacao.setEditable(false);
        btnCodo.setEnabled(false);
    }

    private void LimpaCampos() {
        edtCodo.setText("");
        edtCont.setText("");
        edtDataAssinatura.setText("");
        edtDatafim.setText("");
        edtDuracao.setText("");
        edtNmCodo.setText("");
        edtSetor.setText("");
        edtVlrFim.setText("");
        edtVlrIni.setText("");
        cbSituacao.setSelectedIndex(0);
    }

    private void PreencheCampos() {
        edtCodo.setText(String.valueOf(cl.getCONT_CODFOR()));
        edtCont.setText(cl.getCONT_NOME());
        SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
        edtDataAssinatura.setText(String.valueOf(df.format(cl.getCONT_DATAASSI())));
        edtDatafim.setText(String.valueOf(df.format(cl.getCONT_DATAFIM())));
        edtDuracao.setText(String.valueOf(cl.getCONT_DURACAO()));
        edtVlrFim.setText(String.valueOf(cl.getCONT_VALORFIM()));
        edtVlrIni.setText(String.valueOf(cl.getCONT_VALORINI()));
        cbSituacao.setSelectedItem(cl.getCONT_STATUS());
        PreencheContratado();
        edtSetor.setText(cl.getCONT_SET());
        if (cl.getCONT_TIPODUR() == 0)
            rbDias.setSelected(true);
        else
            rbMes.setSelected(true);
        CarregaAdicAditLiq();
    }

    private void PreencheContratado() {
            ContratadoBUS bus = new ContratadoBUS();
            try 
            {
                clcodo = bus.buscar(cl.getCONT_CODFOR());
                edtNmCodo.setText(clcodo.getCODO_RAZAO());
                edtCodo.setText(String.valueOf(cl.getCONT_CODFOR()));
            } catch (Exception ex) {
                Logger.getLogger(GUICadContratado.class.getName()).log(Level.SEVERE, null, ex);
            }
    }

    private void carregadadoscl() throws ParseException {
        cl.setCONT_NOME(edtCont.getText());
        cl.setCONT_CODFOR(Integer.parseInt(edtCodo.getText()));
        
        java.util.Date date = null;
        try 
        { 
            DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
            cl.setCONT_DATAASSI((java.util.Date)formatter.parse(edtDatafim.getText()));
        }
                catch (ParseException e)
        {
            throw e;  
        } 
        
        date = null;
        try 
        { 
            DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
            cl.setCONT_DATAFIM((java.util.Date)formatter.parse(edtDatafim.getText()));
        }
                catch (ParseException e)
        {
            throw e;  
        } 
        cl.setCONT_DURACAO( Integer.parseInt(edtDuracao.getText()) );
        cl.setCONT_STATUS((String) cbSituacao.getSelectedItem());
        cl.setCONT_VALORFIM(Float.parseFloat(edtVlrFim.getText()));
        cl.setCONT_VALORINI(Float.parseFloat(edtVlrIni.getText()));
        cl.setCONT_SET(edtSetor.getText());
        if (rbDias.isSelected())
            cl.setCONT_TIPODUR(0);
        else
            cl.setCONT_TIPODUR(1);
    }

    private void CarregaAdicAditLiq() {
        
        AdicaoBUS busAdic = new AdicaoBUS();
        try {
            AdicaoTableModel tmAdic = new AdicaoTableModel(busAdic.buscar_contrato(cl.getCONT_COD()));
            tblAdic.setModel(tmAdic);
        } catch (Exception ex) {
            Logger.getLogger(GUIContratadoPesquisar.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        AditamentoBUS busAdit = new AditamentoBUS();
        try {
            AditamentoTableModel tmAdit = new AditamentoTableModel(busAdit.listar(cl.getCONT_COD()));
            tblAdit.setModel(tmAdit);
        } catch (Exception ex) {
            Logger.getLogger(GUIContratadoPesquisar.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        LiquidacaoBUS busLiq = new LiquidacaoBUS();
        try {
            LiquidacaoTableModel tmLiq = new LiquidacaoTableModel(busLiq.listar(cl.getCONT_COD()));
            tblLiq.setModel(tmLiq);
        } catch (Exception ex) {
            Logger.getLogger(GUIContratadoPesquisar.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
